package logic

import (
	"context"
	"srv/shenzhou"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListUserLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListUserLogic {
	return &ListUserLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ListUserLogic) ListUser(req *types.ListUserRequest) (resp *types.Response, err error) {
	list, err := l.svcCtx.ShenzhouSrv.ListUser(l.ctx, &shenzhou.ListUserRequest{State: req.State})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  "获取用户列表失败",
		}, nil
	}
	if req.State == 1 {
		return &types.Response{
			Code: 500,
			Msg:  "获取用户已冻结",
		}, nil
	}

	return &types.Response{
		Code: 200,
		Msg:  "获取用户列表成功",
		Data: map[string]interface{}{
			"list": list,
		},
	}, nil
}
